﻿/*
 *  PassBag is multi-platform software that securely manage/store passwords
 *  Copyright (C) <2009>  <Hugo Rodrigues PEREIRA>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 *  You can find a copy of the GPLv3 at project <root directory>/gpl.txt
 *
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace PassBag.Presentation {
    partial class AboutBoxForm : Form {
        public AboutBoxForm () {
            InitializeComponent ();

            LoadRessource ();
        }

        #region Load Resources

        /// <summary>
        /// Loads the ressource.
        /// </summary>
        private void LoadRessource () {
            this.Text = String.Format ("{0} {1}", Properties.Resources.AboutBoxForm_Title, AssemblyTitle);
            this.labelProductName.Text = AssemblyTitle;
            this.labelVersion.Text = String.Format ("{0} {1}", Properties.Resources.AboutBoxForm_LabelVersion, AssemblyVersion);
            this.labelCopyright.Text = AssemblyCopyright;
            this.labelCompanyName.Text = AssemblyCompany;
            this.textBoxDescription.Text = Properties.Resources.AboutBoxForm_Description;

            this.okButton.Text = Properties.Resources.Global_OkButton;
            this.googleLinkLabel.Text = Properties.Resources.AboutBoxForm_GoogleCodeText;
            this.codeProjectLinkLabel.Text = Properties.Resources.AboutBoxForm_CodeProjectArticleText;
            this.GoToLicenseLinkLabel.Text = Properties.Resources.AboutBoxForm_LicenseText;
        }

        #endregion

        #region Assembly Attribute Accessors

        public static string AssemblyTitle {
            get {
                object[] attributes = Assembly.GetExecutingAssembly ().GetCustomAttributes (typeof (AssemblyTitleAttribute), false);
                if (attributes.Length > 0) {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (! string.IsNullOrEmpty(titleAttribute.Title)) {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension (Assembly.GetExecutingAssembly ().CodeBase);
            }
        }

        public static string AssemblyVersion {
            get {
                return Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
            }
        }

        public static string AssemblyDescription {
            get {
                object[] attributes = Assembly.GetExecutingAssembly ().GetCustomAttributes (typeof (AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0) {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public static string AssemblyProduct {
            get {
                object[] attributes = Assembly.GetExecutingAssembly ().GetCustomAttributes (typeof (AssemblyProductAttribute), false);
                if (attributes.Length == 0) {
                    return string.Empty;
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public static string AssemblyCopyright {
            get {
                object[] attributes = Assembly.GetExecutingAssembly ().GetCustomAttributes (typeof (AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0) {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public static string AssemblyCompany {
            get {
                object[] attributes = Assembly.GetExecutingAssembly ().GetCustomAttributes (typeof (AssemblyCompanyAttribute), false);
                if (attributes.Length == 0) {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion

        private void googleLinkLabel_LinkClicked (object sender, LinkLabelLinkClickedEventArgs e) {
            PassBag.Utils.WebTools.Navigate (Properties.Resources.AboutBoxForm_GoogleCodeLink);
        }

        private void codeProjectLinkLabel_LinkClicked (object sender, LinkLabelLinkClickedEventArgs e) {
            PassBag.Utils.WebTools.Navigate (Properties.Resources.AboutBoxForm_CodeProjectArticleLink);
        }

        private void GoToLicenseLinkLabel_LinkClicked (object sender, LinkLabelLinkClickedEventArgs e) {
            PassBag.Utils.WebTools.Navigate (Properties.Resources.AboutBoxForm_LicenseLink);
        }
    }
}
